home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’93
/
Jon’s FKEYs
/
FKEYList ƒ
/
FKEYList FKEY.p
< prev
next >
Wrap
Text File
|
1992-09-28
|
4KB
|
181 lines
{ FKEYList FKEY © 1992 by Jon Wind }
{ Version 1.0 on 9/28/92 }
{ This FKEY lets you draw a rectangle on the screen and displays it's coordinates. }
{ Thanks to Brad Pettit and his colorfkey for his method of conditional compilation. }
{ To execute this as a program... }
{ 1. change the definition of fkey to false }
{ 2. set the project type to application }
{ 3. change the library from drvrruntime.lib to µruntime.lib }
{ 4. rebuild the project}
{$setc fkey := true}
{$ifc fkey}
unit FKEYList;
interface
procedure main;
implementation
{$elsec}
program FKEYList;
{$endc}
procedure main;
const
kCredits = 'FKEYList 1.0 by Jon Wind';
kFont = 'Chicago';
kRezType = 'FKEY';
kWidth = 380;
kNameCol = 34;
kIDCol = 264;
kIDCol_15 = 249;
kNameTitle = 'Name';
kIDTitle = 'Command Key';
kNoFKEYsMsg = 'No FKEYs installed';
type
FKEYrec = record
ID: Integer;
Name: StringHandle;
end;
FKEYArray = array[1..1] of FKEYrec;
FKEYArrayPtr = ^FKEYArray;
FKEYArrayHandle = ^FKEYArrayPtr;
var
theWindow: WindowPtr;
winRect: Rect;
savePort: GrafPtr;
p: grafport;
theEvent: EventRecord;
done: Boolean;
i, theFont, iCnt, rezID, j, minIndx, row: Integer;
rezType: resType;
rezName: Str255;
numStr: string[7];
rezHdl: Handle;
FKEYs: FKEYArrayHandle;
tempFKEY: FKEYrec;
function aNum2Str (aNum: LongInt): Str255;
{ NumToString procedure available as a function }
var
NumStr: Str255;
begin
NumToString(aNum, NumStr);
aNum2Str := NumStr;
end;
{ --------- Main Procedure --------- }
begin
GetPort(savePort); { save current grafport }
iCnt := CountResources(kRezType);
FKEYs := FKEYArrayHandle(NewHandle(sizeof(FKEYArray) * iCnt));
MoveHHi(Handle(FKEYs));
HLock(Handle(FKEYs));
SetRect(winRect, 0, 0, kWidth, 60 + (iCnt * 16));
if iCnt = 0 then
winRect.bottom := winRect.bottom + 16;
OpenPort(@p);
OffsetRect(winRect, (p.portRect.right - winRect.right) div 2, (p.portRect.bottom - winRect.bottom) div 3);
ClosePort(@p);
{$push}
{$r-}
SetResLoad(False);
for i := 1 to iCnt do
begin
rezHdl := GetIndResource(kRezType, i);
GetResInfo(rezHdl, FKEYs^^[i].ID, rezType, rezName);
if Length(rezName) = 0 then
rezName := '[Untitled]';
FKEYs^^[i].Name := NewString(rezName);
SetString(FKEYs^^[i].Name, rezName);
end;
SetResLoad(True);
for i := 1 to iCnt do { sort array using selection sort method }
begin
minIndx := i;
for j := i + 1 to iCnt do
if FKEYs^^[j].ID < FKEYs^^[minIndx].ID then
minIndx := j;
tempFKEY := FKEYs^^[i];
FKEYs^^[i] := FKEYs^^[minIndx];
FKEYs^^[minIndx] := tempFKEY;
end;
{$pop}
theWindow := NewWindow(nil, winRect, '', True, altDBoxProc, Pointer(-1), False, 0);
SetPort(theWindow);
GetFNum(kFont, theFont);
TextFont(theFont);
TextFace([underline]);
Moveto(kNameCol, 20);
DrawString(kNameTitle);
Moveto(kIDCol_15, 20);
DrawString(kIDTitle);
TextFace([]);
{$push}
{$r-}
if iCnt > 0 then
for i := 1 to iCnt do
begin
rezID := FKEYs^^[i].ID;
numStr := aNum2Str(rezID);
row := 26 + (i * 16);
Moveto(kNameCol, row);
DrawString(FKEYs^^[i].Name^^);
Moveto(kIDCol, row);
if (rezID >= 0) and (rezID <= 9) then
DrawString(Concat('-Shift-', numStr))
else
DrawString(Concat('N/A [#', numStr, ']'));
DisposHandle(Handle(FKEYs^^[i].Name));
end
else
begin
Moveto(kNameCol, 42); {26 + 16}
DrawString(kNoFKEYsMsg);
end;
{$pop}
Moveto((kWidth - StringWidth(kCredits)) div 2, theWindow^.portRect.bottom - 8);
DrawString(kCredits);
HUnlock(Handle(FKEYs));
DisposHandle(Handle(FKEYs));
repeat
until GetOSEvent(mDownMask + keyDownMask, theEvent);{everyEvent}
DisposeWindow(theWindow);
{• InitCursor;•}
SetPort(savePort); { restore grafport }
end; { main }
{$ifc fkey = false}
begin
main;
{$endc}
end.